//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
#include "ListAmylogenic.h"

#include <string.h>
#include <stdlib.h>
#include <vector>

#include <iostream>
#include <fstream>
//#include <asm-generic/sockios.h>
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
#define  LENGTHLINE     500000
#define  RANGE          100
#define  PERCENTSPLIT   10
#define  REPETITIONS    10
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
using namespace std;
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
namespace AmylogenicSpace {

  bool FindData(TNode <AmylogenicData>* NodeT, void* ref = NULL) {
    
    char* query  = (char*)ref;
    char* target = NodeT->Info()->Id()->Out();
    char* part   = strtok(query, "> \t\r\n");
    
    while (part) {
      if (!strstr(target, part)) return false;
      part = strtok(NULL, "> \t\r\n");
    }
    
    return true;
    
  }
  
  bool FindShuffle(TNode <String>* NodeT, void* ref = NULL) {
    
    char* query  = (char*)ref;
    char* target = NodeT->Info()->Out();
    char* part   = strtok(query, "> \t\r\n");
    
    while (part) {
      if (!strstr(target, part)) return false;
      part = strtok(NULL, "> \t\r\n");
    }
    
    return true;
    
  }
  
  bool MatchData(TNode <AmylogenicData>* NodeT, void* ref = NULL) {
    
    char* target = (char*)ref;
    char* query  = NodeT->Info()->Id()->Out();
    char* part   = strtok(query, "> \t\r\n");
    
    while (part) {
      if (!strstr(target, part)) return false;
      part = strtok(NULL, "> \t\r\n");
    }
    
    return true;
    
  }
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
ListAmylogenic::ListAmylogenic() {
  
  this->filenameFASTASeq              = new String ();
  this->filenameAmylogenicSeq         = new String ();

  this->filenameFASTASeqShuffle       = new String ();
  this->filenameAmylogenicSeqShuffle  = new String ();

  this->filenameOut                   = new String ();

  this->listAmylogenicData            = new TListE <AmylogenicData> ();
  
  for (int i = 0; i < AMOUNTAA; i++) 
    this->frequencyAA[i]        = 0;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
ListAmylogenic::ListAmylogenic(const ListAmylogenic& listAmylogenic) {
  
  this->filenameFASTASeq              = new String (listAmylogenic.filenameFASTASeq);
  this->filenameAmylogenicSeq         = new String (listAmylogenic.filenameAmylogenicSeq);

  this->filenameFASTASeqShuffle       = new String (listAmylogenic.filenameFASTASeqShuffle);
  this->filenameAmylogenicSeqShuffle  = new String (listAmylogenic.filenameAmylogenicSeqShuffle);

  this->filenameOut                   = new String (listAmylogenic.filenameOut);

  this->listAmylogenicData            = new TListE <AmylogenicData> (listAmylogenic.listAmylogenicData);
  
  for (int i = 0; i < AMOUNTAA; i++) 
    this->frequencyAA[i]        = listAmylogenic.frequencyAA[i];

}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
ListAmylogenic::ListAmylogenic(const ListAmylogenic* listAmylogenic) {

  this->filenameFASTASeq              = new String (listAmylogenic->filenameFASTASeq);
  this->filenameAmylogenicSeq         = new String (listAmylogenic->filenameAmylogenicSeq);

  this->filenameFASTASeqShuffle       = new String (listAmylogenic->filenameFASTASeqShuffle);
  this->filenameAmylogenicSeqShuffle  = new String (listAmylogenic->filenameAmylogenicSeqShuffle);

  this->filenameOut                   = new String (listAmylogenic->filenameOut);

  this->listAmylogenicData            = new TListE <AmylogenicData> (listAmylogenic->listAmylogenicData);

  for (int i = 0; i < AMOUNTAA; i++) 
    this->frequencyAA[i]        = listAmylogenic->frequencyAA[i];
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
ListAmylogenic::~ListAmylogenic() {

  if (this->filenameFASTASeq)             delete this->filenameFASTASeq;
  if (this->filenameAmylogenicSeq)        delete this->filenameAmylogenicSeq;
  if (this->filenameFASTASeqShuffle)      delete this->filenameFASTASeqShuffle;
  if (this->filenameAmylogenicSeqShuffle) delete this->filenameAmylogenicSeqShuffle;
  if (this->filenameOut)                  delete this->filenameOut;
  if (this->listAmylogenicData)           delete this->listAmylogenicData;

  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void ListAmylogenic::FilenameFASTASeq(String* filenameFASTASeq) {
  if (filenameFASTASeq) this->filenameFASTASeq->In(filenameFASTASeq);  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void ListAmylogenic::FilenameAmylogenicSeq(String* filenameAmylogenicSeq) {
  if (filenameAmylogenicSeq) this->filenameAmylogenicSeq->In(filenameAmylogenicSeq);  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void ListAmylogenic::FilenameFASTASeqShuffle(String* filenameFASTASeqShuffle) {
  if (filenameFASTASeqShuffle) this->filenameFASTASeqShuffle->In(filenameFASTASeqShuffle);  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void ListAmylogenic::FilenameAmylogenicSeqShuffle(String* filenameAmylogenicSeqShuffle) {
  if (filenameAmylogenicSeqShuffle) this->filenameAmylogenicSeqShuffle->In(filenameAmylogenicSeqShuffle);  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void ListAmylogenic::FilenameOut(String* filenameOut) {
  if (filenameOut) this->filenameOut->In(filenameOut);  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void ListAmylogenic::ListAmylogenicData(TListE <AmylogenicData>* listAmylogenicData) {
  if (listAmylogenicData) *(this->listAmylogenicData) = *(listAmylogenicData);  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
String* ListAmylogenic::FilenameFASTASeq(void) {
  return this->filenameFASTASeq;  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
String* ListAmylogenic::FilenameAmylogenicSeq(void) {
  return this->filenameAmylogenicSeq;  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
String* ListAmylogenic::FilenameFASTASeqShuffle(void) {
  return this->filenameFASTASeqShuffle;  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
String* ListAmylogenic::FilenameAmylogenicSeqShuffle(void) {
  return this->filenameAmylogenicSeqShuffle;  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
String* ListAmylogenic::FilenameOut(void) {
  return this->filenameOut;  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
TListE <AmylogenicData>* ListAmylogenic::ListAmylogenicData(void) {
  return this->listAmylogenicData;  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool ListAmylogenic::LoadData(void) {
  
  if (!this->filenameFASTASeq->Length()      || !this->filenameFASTASeqShuffle->Length()       || 
      !this->filenameAmylogenicSeq->Length() || !this->filenameAmylogenicSeqShuffle->Length()) 
    return false;
  
  fstream fileFASTASeq, fileFASTASeqShuffle, fileAmylogenicSeq, fileAmylogenicSeqShuffle;
  
  long counterShuffleSequence         = 0;
  long counterAmylSeq                 = 0;
  long counterAmylShuffleSeq          = 0;  
  
  long counterShuffleSequenceNotFound = 0;
  long counterAmylSeqNotFound         = 0;
  long counterAmylShuffleSeqNotFound  = 0;  
  
  //--
  
  fileFASTASeq.open(this->filenameFASTASeq->Out(), fstream::in);
  
  if (fileFASTASeq.is_open()) {
    
    char  buffer[LENGTHLINE + 1], bufferT[LENGTHLINE + 1];
    
    while (!fileFASTASeq.eof()) {
      
      AmylogenicData *data = new AmylogenicData();
      
      fileFASTASeq.getline(buffer, LENGTHLINE);
      
      data->Id(buffer + 1);
      data->Id()->Trim();
      
      fileFASTASeq.getline(buffer, LENGTHLINE);
      
      data->Sequence(buffer);
      data->Sequence()->Trim();
      
      this->listAmylogenicData->Add(data);
      
    }
    
    fileFASTASeq.close();

    //--
    
    fileAmylogenicSeq.open(this->filenameAmylogenicSeq->Out(), fstream::in);
    
    if (fileAmylogenicSeq.is_open()) {
      
      while (!fileAmylogenicSeq.eof()) {
        
        fileAmylogenicSeq.getline(buffer, LENGTHLINE);
        cout << buffer << endl;
        
        strcpy(bufferT, buffer);
        char* query   = strtok(bufferT, "#\n\t");
        
        AmylogenicData* find = this->listAmylogenicData->FirstOcurrence(AmylogenicSpace::FindData, query);
        
        if (find && find->NumberAmylogenicRegions() == -1) { 
          cout << "Founded - Amyloidogenic" << endl;
          find->ReadAmylogenicRegionsSequence(buffer);
          counterAmylSeq++;
        }
        else if (!find) { cout << "Not found" << endl; counterAmylSeqNotFound++; }
        
      }
      
      fileAmylogenicSeq.close();
      
    }
    else return false;
    
    //--

    fileFASTASeqShuffle.open(this->filenameFASTASeqShuffle->Out(), fstream::in);
    
    if (fileFASTASeqShuffle.is_open()) {
      
      while (!fileFASTASeqShuffle.eof()) {
        
        fileFASTASeqShuffle.getline(buffer, LENGTHLINE);
        cout << buffer << endl;
        strcpy(bufferT, buffer);
        
        AmylogenicData* find = this->listAmylogenicData->FirstOcurrence(AmylogenicSpace::MatchData, bufferT);
        
        if (find && !fileFASTASeqShuffle.eof()) {
          cout << "Founded - Shuffle" << endl;
          find->Description(buffer);
          fileFASTASeqShuffle.getline(buffer, LENGTHLINE);
          find->SequencesShuffle()->In(buffer);
          find->SequencesShuffle()->Trim();
          counterShuffleSequence++;
        }
        else if (!find) { cout << "Not found" << endl; counterShuffleSequenceNotFound++; }
        
      }
      
      fileFASTASeqShuffle.close();
      
    }
    else return false;
    
    //--

    fileAmylogenicSeqShuffle.open(this->filenameAmylogenicSeqShuffle->Out(), fstream::in);
    
    if (fileAmylogenicSeqShuffle.is_open()) {
      
      while (!fileAmylogenicSeqShuffle.eof()) {
        
        fileAmylogenicSeqShuffle.getline(buffer, LENGTHLINE);
        cout << buffer << endl;

        strcpy(bufferT, buffer);
        AmylogenicData* find = this->listAmylogenicData->FirstOcurrence(AmylogenicSpace::MatchData, bufferT);

        if (find && find->NumberAmylogenicRegionsShuffle() == -1) {
          cout << "Founded Amyloidogenic Shuffle" << endl;
          find->AddAmylogenicRegionsSequenceShuffle(buffer);
          counterAmylShuffleSeq++;
        }
        else if (!find) { cout << "Not found" << endl; counterAmylShuffleSeqNotFound++; }
 
      }
      
      fileFASTASeqShuffle.close();
      
    }
    else return false;
    
  }
  else return false;
  
  cout << "------------------------------------------------------------------" << endl;
  cout << "                                  Amount of Sequences: " << this->listAmylogenicData->Length() << endl;
  cout << "            Amount of Amyloidogenic Sequences Founded:" << counterAmylSeq << endl;
  cout << "        Amount of Amyloidogenic Sequences Not Founded:" << counterAmylSeqNotFound << endl;
  cout << "                  Amount of Shuffle Sequences Founded:" << counterShuffleSequence << endl;
  cout << "              Amount of Shuffle Sequences Not Founded:" << counterShuffleSequenceNotFound << endl;
  cout << "    Amount of Shuffle Amyloidogenic Sequences Founded:" << counterAmylShuffleSeq << endl;
  cout << "Amount of Shuffle Amyloidogenic Sequences Not Founded:" << counterAmylShuffleSeqNotFound << endl;
  cout << "------------------------------------------------------------------" << endl;
  
  return true;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool ListAmylogenic::GetListSeqAmylogenicRegions(String* filenameOut) {
  
  if (!filenameOut) return false;
  
  fstream fileOut;
  
  fileOut.open(filenameOut->Out(), fstream::out);
  
  if (!fileOut.is_open()) return false;
  
  this->listAmylogenicData->SetInitial();
  while (this->listAmylogenicData->SetNext()) 
    if (this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegions() != 0 && this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegions() != -1) {
      fileOut << ">" << this->listAmylogenicData->GetCurrent()->Id()->Out() << endl << this->listAmylogenicData->GetCurrent()->Sequence()->Out() << endl;
      cout    << ">" << this->listAmylogenicData->GetCurrent()->Id()->Out() << endl << this->listAmylogenicData->GetCurrent()->Sequence()->Out() << endl;
    }

  fileOut.close();
  
  return true;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool ListAmylogenic::GetListSeqNoAmylogenicRegions(String* filenameOut) {
  
  if (!filenameOut) return false;
  
  fstream fileOut;
  
  fileOut.open(filenameOut->Out(), fstream::out);
  
  if (!fileOut.is_open()) return false;
  
  this->listAmylogenicData->SetInitial();
  while (this->listAmylogenicData->SetNext()) 
    if (!(this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegions())) {
      fileOut << ">" << this->listAmylogenicData->GetCurrent()->Id()->Out() << endl << this->listAmylogenicData->GetCurrent()->Sequence()->Out() << endl;
      cout    << ">" << this->listAmylogenicData->GetCurrent()->Id()->Out() << endl << this->listAmylogenicData->GetCurrent()->Sequence()->Out() << endl;
    }

  fileOut.close();
  
  return true;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool ListAmylogenic::GetListSeqShuffleAmylogenicRegions(String* filenameOut) {
  
  if (!filenameOut) return false;
  
  fstream fileOut;
  
  fileOut.open(filenameOut->Out(), fstream::out);
  
  if (!fileOut.is_open()) return false;
  
  this->listAmylogenicData->SetInitial();
  while (this->listAmylogenicData->SetNext()) {
    if (this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegionsShuffle() != 0 && this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegionsShuffle() != -1) {
      fileOut << ">" << this->listAmylogenicData->GetCurrent()->Id()->Out() << endl << this->listAmylogenicData->GetCurrent()->Sequence()->Out() << endl;
      cout    << ">" << this->listAmylogenicData->GetCurrent()->Id()->Out() << endl << this->listAmylogenicData->GetCurrent()->Sequence()->Out() << endl;
    }
  }
    
  fileOut.close();
  
  return true;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool ListAmylogenic::GetListSeqShuffleNoAmylogenicRegions(String* filenameOut) {
  
  if (!filenameOut) return false;
  
  fstream fileOut;
  
  fileOut.open(filenameOut->Out(), fstream::out);
  
  if (!fileOut.is_open()) return false;
  
  this->listAmylogenicData->SetInitial();
  while (this->listAmylogenicData->SetNext()) {
    if (!(this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegionsShuffle())) {
      fileOut << ">" << this->listAmylogenicData->GetCurrent()->Id()->Out() << endl << this->listAmylogenicData->GetCurrent()->Sequence()->Out() << endl;
      cout    << ">" << this->listAmylogenicData->GetCurrent()->Id()->Out() << endl << this->listAmylogenicData->GetCurrent()->Sequence()->Out() << endl;
    }
  }
    
  fileOut.close();
  
  return true;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool ListAmylogenic::GetListSeqAmylogenicShuffleNoAmylogenicRegions(String* filenameOut) {
  
  if (!filenameOut) return false;
  
  fstream fileOut;
  
  fileOut.open(filenameOut->Out(), fstream::out);
  
  if (!fileOut.is_open()) return false;
  
  this->listAmylogenicData->SetInitial();
  while (this->listAmylogenicData->SetNext()) {
    if (  this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegions() != 0  &&
          this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegions() != -1 &&
        !(this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegionsShuffle())) {
      fileOut << ">" << this->listAmylogenicData->GetCurrent()->Id()->Out() << endl << this->listAmylogenicData->GetCurrent()->Sequence()->Out() << endl;
      cout    << ">" << this->listAmylogenicData->GetCurrent()->Id()->Out() << endl << this->listAmylogenicData->GetCurrent()->Sequence()->Out() << endl;
    }
  }
    
  fileOut.close();
  
  return true;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool ListAmylogenic::GetListSeqNoAmylogenicShuffleAmylogenicRegions(String* filenameOut) {
  
  if (!filenameOut) return false;
  
  fstream fileOut;
  
  fileOut.open(filenameOut->Out(), fstream::out);
  
  if (!fileOut.is_open()) return false;
  
  this->listAmylogenicData->SetInitial();
  while (this->listAmylogenicData->SetNext()) {
    if (!this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegions()             &&
         this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegionsShuffle() != 0 &&
         this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegionsShuffle() != -1) {
      fileOut << ">" << this->listAmylogenicData->GetCurrent()->Id()->Out() << endl << this->listAmylogenicData->GetCurrent()->Sequence()->Out() << endl;
      cout    << ">" << this->listAmylogenicData->GetCurrent()->Id()->Out() << endl << this->listAmylogenicData->GetCurrent()->Sequence()->Out() << endl;
    }
  }
    
  fileOut.close();
  
  return true;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool ListAmylogenic::GetListSeqAmylogenicShuffleAmylogenicRegions(String* filenameOut) {
  
  if (!filenameOut) return false;
  
  fstream fileOut;
  
  fileOut.open(filenameOut->Out(), fstream::out);
  
  if (!fileOut.is_open()) return false;
  
  this->listAmylogenicData->SetInitial();
  while (this->listAmylogenicData->SetNext()) {
    if (this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegions()        !=  0 &&
        this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegions()        != -1 &&
        this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegionsShuffle() !=  0 &&
        this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegionsShuffle() != -1) {
      fileOut << ">" << this->listAmylogenicData->GetCurrent()->Id()->Out() << endl << this->listAmylogenicData->GetCurrent()->Sequence()->Out() << endl;
      cout    << ">" << this->listAmylogenicData->GetCurrent()->Id()->Out() << endl << this->listAmylogenicData->GetCurrent()->Sequence()->Out() << endl;
    }
  }
    
  fileOut.close();
  
  return true;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool ListAmylogenic::GetListSeqNoAmylogenicShuffleNoAmylogenicRegions(String* filenameOut) {
  
  if (!filenameOut) return false;
  
  fstream fileOut;
  
  fileOut.open(filenameOut->Out(), fstream::out);
  
  if (!fileOut.is_open()) return false;
  
  this->listAmylogenicData->SetInitial();
  while (this->listAmylogenicData->SetNext()) {
    if (!(this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegions()) &&
        !(this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegionsShuffle())) {
      fileOut << ">" << this->listAmylogenicData->GetCurrent()->Id()->Out() << endl << this->listAmylogenicData->GetCurrent()->Sequence()->Out() << endl;
      cout    << ">" << this->listAmylogenicData->GetCurrent()->Id()->Out() << endl << this->listAmylogenicData->GetCurrent()->Sequence()->Out() << endl;
    }
  }
    
  fileOut.close();
  
  return true;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool ListAmylogenic::GetFreqAAListSeqAmylogenicRegions(String* filenameOut) {
  
  if (!filenameOut) return false;
  
  this->CleanFrequencyAA();
  
  int counter = 0;
  
  this->listAmylogenicData->SetInitial();
  while (this->listAmylogenicData->SetNext()) 
    if (this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegions() !=  0  && 
        this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegions() != -1) {
      this->SumFrequencyAA(this->listAmylogenicData->GetCurrent()->GetFrequencyAASequence());
      counter++;
    }
  
  fstream fileOut;
  fileOut.open(filenameOut->Out(), fstream::out);
  if (!fileOut.is_open()) return false;
  
  char aminoAcids[] = { "ACDEFGHIKLMNPQRSTVWYX" };
  
  fileOut << "AA FreqN" << endl;
  cout    << "AA FreqN" << endl;
  
  for (int i = 0; i < AMOUNTAA; i++) {
    
    if (counter) this->frequencyAA[i] /= (double)counter;
    else         this->frequencyAA[i]  = 0;
    
    fileOut << aminoAcids[i] << "  " << this->frequencyAA[i] << endl;
    cout    << aminoAcids[i] << "  " << this->frequencyAA[i] << endl;
        
  }
  
  fileOut.close();
  
  return true;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool ListAmylogenic::GetFreqAAListSeqNoAmylogenicRegions(String* filenameOut) {
  
  if (!filenameOut) return false;
  
  this->CleanFrequencyAA();
  
  int counter = 0;
  
  this->listAmylogenicData->SetInitial();
  while (this->listAmylogenicData->SetNext()) {
    cout << this->listAmylogenicData->GetCurrent()->Id()->Out() << " - " << this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegions() << endl;
    if (!this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegions()) {
      this->SumFrequencyAA(this->listAmylogenicData->GetCurrent()->GetFrequencyAASequence());
      counter++;
    }
  }
  
  fstream fileOut;
  fileOut.open(filenameOut->Out(), fstream::out);
  if (!fileOut.is_open()) return false;
  
  char aminoAcids[] = { "ACDEFGHIKLMNPQRSTVWYX" };
  
  fileOut << "AA FreqN" << endl;
  cout    << "AA FreqN" << endl;
  
  for (int i = 0; i < AMOUNTAA; i++) {
    
    if (counter) this->frequencyAA[i] /= (double)counter;
    else         this->frequencyAA[i]  = 0;
    
    fileOut << aminoAcids[i] << "  " << this->frequencyAA[i] << endl;
    cout    << aminoAcids[i] << "  " << this->frequencyAA[i] << endl;
        
  }

  fileOut.close();
  
  return true;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool ListAmylogenic::GetFreqAAListSeqShuffleAmylogenicRegions(String* filenameOut) {
  
  if (!filenameOut) return false;
  
  this->CleanFrequencyAA();
  
  int counter = 0;
  
  this->listAmylogenicData->SetInitial();
  while (this->listAmylogenicData->SetNext()) 
    if (this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegionsShuffle() !=  0 &&
        this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegionsShuffle() != -1) {
      this->SumFrequencyAA(this->listAmylogenicData->GetCurrent()->GetFrequencyAASequence());
      counter++;
    }
  
  fstream fileOut;
  fileOut.open(filenameOut->Out(), fstream::out);
  if (!fileOut.is_open()) return false;
  
  char aminoAcids[] = { "ACDEFGHIKLMNPQRSTVWYX" };
  
  fileOut << "AA FreqN" << endl;
  cout    << "AA FreqN" << endl;
  
  for (int i = 0; i < AMOUNTAA; i++) {
    
    if (counter) this->frequencyAA[i] /= (double)counter;
    else         this->frequencyAA[i]  = 0;
    
    fileOut << aminoAcids[i] << "  " << this->frequencyAA[i] << endl;
    cout    << aminoAcids[i] << "  " << this->frequencyAA[i] << endl;
        
  }

  fileOut.close();
  
  return true;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool ListAmylogenic::GetFreqAAListSeqShuffleNoAmylogenicRegions(String* filenameOut) {
  
  if (!filenameOut) return false;
  
  this->CleanFrequencyAA();
  
  int counter = 0;
  
  this->listAmylogenicData->SetInitial();
  while (this->listAmylogenicData->SetNext()) 
    if (!(this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegionsShuffle())) {
      this->SumFrequencyAA(this->listAmylogenicData->GetCurrent()->GetFrequencyAASequence());
      counter++;
    }
  
  fstream fileOut;
  fileOut.open(filenameOut->Out(), fstream::out);
  if (!fileOut.is_open()) return false;
  
  char aminoAcids[] = { "ACDEFGHIKLMNPQRSTVWYX" };
  
  fileOut << "AA FreqN" << endl;
  cout    << "AA FreqN" << endl;
  
  for (int i = 0; i < AMOUNTAA; i++) {
    
    if (counter) this->frequencyAA[i] /= (double)counter;
    else         this->frequencyAA[i]  = 0;
    
    fileOut << aminoAcids[i] << "  " << this->frequencyAA[i] << endl;
    cout    << aminoAcids[i] << "  " << this->frequencyAA[i] << endl;
        
  }

  fileOut.close();
  
  return true;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool ListAmylogenic::GetFreqAAListSeqAmylogenicShuffleNoAmylogenicRegions(String* filenameOut) {
  
  if (!filenameOut) return false;
  
  this->CleanFrequencyAA();
  
  int counter = 0;
  
  this->listAmylogenicData->SetInitial();
  while (this->listAmylogenicData->SetNext()) 
    if (  this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegions() !=  0 &&
          this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegions() != -1 &&
        !(this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegionsShuffle())) {
      this->SumFrequencyAA(this->listAmylogenicData->GetCurrent()->GetFrequencyAASequence());
      counter++;
    }
  
  fstream fileOut;
  fileOut.open(filenameOut->Out(), fstream::out);
  if (!fileOut.is_open()) return false;
  
  char aminoAcids[] = { "ACDEFGHIKLMNPQRSTVWYX" };
  
  fileOut << "AA FreqN" << endl;
  cout    << "AA FreqN" << endl;
  
  for (int i = 0; i < AMOUNTAA; i++) {
    
    if (counter) this->frequencyAA[i] /= (double)counter;
    else         this->frequencyAA[i]  = 0;
    
    fileOut << aminoAcids[i] << "  " << this->frequencyAA[i] << endl;
    cout    << aminoAcids[i] << "  " << this->frequencyAA[i] << endl;
        
  }

  fileOut.close();
  
  return true;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool ListAmylogenic::GetFreqAAListSeqNoAmylogenicShuffleAmylogenicRegions(String* filenameOut) {
  
  if (!filenameOut) return false;
  
  this->CleanFrequencyAA();
  
  int counter = 0;
  
  this->listAmylogenicData->SetInitial();
  while (this->listAmylogenicData->SetNext()) 
    if (!this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegions()              &&
         this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegionsShuffle() !=  0 &&
         this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegionsShuffle() != -1) {
      this->SumFrequencyAA(this->listAmylogenicData->GetCurrent()->GetFrequencyAASequence());
      counter++;
    }
  
  fstream fileOut;
  fileOut.open(filenameOut->Out(), fstream::out);
  if (!fileOut.is_open()) return false;
  
  char aminoAcids[] = { "ACDEFGHIKLMNPQRSTVWYX" };
  
  fileOut << "AA FreqN" << endl;
  cout    << "AA FreqN" << endl;
  
  for (int i = 0; i < AMOUNTAA; i++) {
    
    if (counter) this->frequencyAA[i] /= (double)counter;
    else         this->frequencyAA[i]  = 0;
    
    fileOut << aminoAcids[i] << "  " << this->frequencyAA[i] << endl;
    cout    << aminoAcids[i] << "  " << this->frequencyAA[i] << endl;
        
  }

  fileOut.close();
  
  return true;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool ListAmylogenic::GetFreqAAListSeqAmylogenicShuffleAmylogenicRegions(String* filenameOut) {
  
  if (!filenameOut) return false;
  
  this->CleanFrequencyAA();
  
  int counter = 0;
  
  this->listAmylogenicData->SetInitial();
  while (this->listAmylogenicData->SetNext()) 
    if (this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegions()        !=  0 &&
        this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegions()        != -1 &&
        this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegionsShuffle() !=  0 &&
        this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegionsShuffle() != -1) {
      this->SumFrequencyAA(this->listAmylogenicData->GetCurrent()->GetFrequencyAASequence());
      counter++;
    }
  
  fstream fileOut;
  fileOut.open(filenameOut->Out(), fstream::out);
  if (!fileOut.is_open()) return false;
  
  char aminoAcids[] = { "ACDEFGHIKLMNPQRSTVWYX" };
  
  fileOut << "AA FreqN" << endl;
  cout    << "AA FreqN" << endl;
  
  for (int i = 0; i < AMOUNTAA; i++) {
    
    if (counter) this->frequencyAA[i] /= (double)counter;
    else         this->frequencyAA[i]  = 0;
    
    fileOut << aminoAcids[i] << "  " << this->frequencyAA[i] << endl;
    cout    << aminoAcids[i] << "  " << this->frequencyAA[i] << endl;
        
  }

  fileOut.close();
  
  return true;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool ListAmylogenic::GetFreqAAListSeqNoAmylogenicShuffleNoAmylogenicRegions(String* filenameOut) {
  
  if (!filenameOut) return false;
  
  this->CleanFrequencyAA();
  
  int counter = 0;
  
  this->listAmylogenicData->SetInitial();
  while (this->listAmylogenicData->SetNext()) 
    if (!(this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegions()) &&
        !(this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegionsShuffle())) {
      this->SumFrequencyAA(this->listAmylogenicData->GetCurrent()->GetFrequencyAASequence());
      counter++;
    }
  
  fstream fileOut;
  fileOut.open(filenameOut->Out(), fstream::out);
  if (!fileOut.is_open()) return false;
  
  char aminoAcids[] = { "ACDEFGHIKLMNPQRSTVWYX" };
  
  fileOut << "AA FreqN" << endl;
  cout    << "AA FreqN" << endl;
  
  for (int i = 0; i < AMOUNTAA; i++) {
    
    if (counter) this->frequencyAA[i] /= (double)counter;
    else         this->frequencyAA[i]  = 0;
    
    fileOut << aminoAcids[i] << "  " << this->frequencyAA[i] << endl;
    cout    << aminoAcids[i] << "  " << this->frequencyAA[i] << endl;
        
  }

  fileOut.close();
  
  return true;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool ListAmylogenic::IsCompleteData(int position) {
  
  if (position < 0 || position >= this->listAmylogenicData->Length()) return false;
  
  if (!this->listAmylogenicData->Get(position)->Id()->Length())                 return false;
  if (!this->listAmylogenicData->Get(position)->Sequence()->Length())           return false;
  if (!this->listAmylogenicData->Get(position)->AmylogenicRegions()->Length())  return false;

  if (!this->listAmylogenicData->Get(position)->Description()->Length())        return false;
  if (!this->listAmylogenicData->Get(position)->SequencesShuffle()->Length())   return false;
  if (!this->listAmylogenicData->Get(position)->AmylogenicRegionsShuffle()->Length() ||
      !this->listAmylogenicData->Get(position)->AmylogenicRegionsShuffle()->Length())   
    return false;

  return true;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool ListAmylogenic::CleanFrequencyAA(void) {
  
  for (int i = 0; i < AMOUNTAA; i++) 
    this->frequencyAA[i] = 0;
  
  return true;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool ListAmylogenic::AssignFrequencyAA(double* data) {
  
  if (!data) return false;
  for (int i = 0; i < AMOUNTAA; i++) this->frequencyAA[i] = data[i];
  return true;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool ListAmylogenic::SumFrequencyAA(double* data) { 
  
  if (!data) return false;
  for (int i = 0; i < AMOUNTAA; i++) this->frequencyAA[i] += data[i];
  return true;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool ListAmylogenic::GetFreqPercentAmylogenicRegions(String* filenameOut) {
 
  if (!filenameOut) return false;
  
  int ranges[RANGE/2];
  int rangesShuffle[RANGE/2];
  
  for (int i = 0; i < RANGE/2; i++) { ranges[i] = 0; rangesShuffle[i] = 0; }
  
  this->listAmylogenicData->SetInitial();
  while (this->listAmylogenicData->SetNext()) {
    ranges[(int)this->listAmylogenicData->GetCurrent()->PercentAmylogenicRegions()/2]++;
    rangesShuffle[(int)(this->listAmylogenicData->GetCurrent()->PercentAmylogenicRegionsShuffle())/2]++;    
  }
  
  fstream fileOut;
  fileOut.open(filenameOut->Out(), fstream::out);
  
  if (!fileOut.is_open()) return false;
  
  fileOut << "Range FreqAR_N FreAR_S" << endl; 
  cout    << "Range FreqAR_N FreAR_S" << endl; 
    
  for (int i = 0; i < RANGE/2; i++) {
    fileOut << i*2 << " " << ranges[i] << " " << rangesShuffle[i] << endl;
    cout    << i*2 << " " << ranges[i] << " " << rangesShuffle[i] << endl;
  }
  
  fileOut.close();
  
  return true;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool ListAmylogenic::GetPercentOfSeqAmylogenicRegions(String* filenameOut) {

  if (!filenameOut || !filenameOut->Length()) return false;
  
  this->DeleteIncompleteData();
  
  fstream fileOut;
  int     sizePercent = (int)(PERCENTSPLIT * this->listAmylogenicData->Length() / 100);
  
  fileOut.open(filenameOut->Out(), fstream::out);
  
  if (!fileOut.is_open()) return false;

  fileOut.width(60); fileOut.left; fileOut << " Name |";
  fileOut.width(20); fileOut.left; fileOut << " Total Sequences |";
  fileOut.width(20); fileOut.left; fileOut << " Seq. Amyl. Reg. |";
  fileOut.width(20); fileOut.left; fileOut << " % |";
  fileOut.width(20); fileOut.left; fileOut << " Size of Part.(E) |";
  fileOut.width(21); fileOut.left; fileOut << " Number of Rep. (E) |";
  
  for (int i = 0; i < REPETITIONS; i++) {
    fileOut.width(23); fileOut.left; fileOut << " Average % in Rep. ";
    fileOut.width(2);  fileOut.left; fileOut << i + 1 << "|";
    fileOut.width(23); fileOut.left; fileOut << " Minimum % in Rep. ";
    fileOut.width(2);  fileOut.left; fileOut << i + 1 << "|";
    fileOut.width(23); fileOut.left; fileOut << " Maximum % in Rep. ";
    fileOut.width(2);  fileOut.left; fileOut << i + 1 << "|"; 
  }
  
  fileOut.width(25); fileOut.left; fileOut << " Average |";
  fileOut.width(25); fileOut.left; fileOut << " Minimun Average |";
  fileOut.width(25); fileOut.left; fileOut << " Maximun Average |";
  fileOut.width(25); fileOut.left; fileOut << " Error Average |";
  
  fileOut << endl;
  
  for (int i = 0; i < 1041; i++) fileOut << "_";
  fileOut << endl;
    
  fileOut.width(58); fileOut.left; fileOut << this->filenameOut->Out() << " |";
  fileOut.width(18); fileOut.left; fileOut << this->listAmylogenicData->Length() << " |";
  
  int counterAmylSeq = 0;
  
  this->listAmylogenicData->SetInitial();
  while (this->listAmylogenicData->SetNext()) 
    if (this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegions() > 0) 
      counterAmylSeq++;
  
  double percentAmyloid = (double)((double)(counterAmylSeq*100)/(double)this->listAmylogenicData->Length());
  
  fileOut.width(18); fileOut.left; fileOut << counterAmylSeq << " |";
  fileOut.width(18); fileOut.left; fileOut << percentAmyloid << " |";
  fileOut.width(18); fileOut.left; fileOut << sizePercent << " |";
  fileOut.width(19); fileOut.left; fileOut << REPETITIONS << " |";
  
  vector <int> arrList;
  double       totalAverage   = 0;
  double       minimumAverage = 0;
  double       maximumAverage = 0;
  
  for (int i = 0; i < REPETITIONS; i++) {
    
    arrList.clear();
    for (int j = 0; j < this->listAmylogenicData->Length(); j++) 
      arrList.push_back(j);
    
    int          numberBinds = (int)(this->listAmylogenicData->Length() / sizePercent) + (((this->listAmylogenicData->Length() % sizePercent))?1:0);
    double       minimum = 0, maximum = 0, average = 0;
    
    vector <int> binds[numberBinds];

    for (int j = 0; j < numberBinds; j++) { 
      int counterComplete = 0;
      while (arrList.size() && (++counterComplete <= sizePercent)) {
        int randomPosition = rand() % arrList.size();
        binds[j].push_back(arrList.at(randomPosition));
        arrList.erase(arrList.begin() + randomPosition);
      }
    }
    
    for (int j = 0; j < REPETITIONS; j++) {
     
      int counterAmylSeqPart = 0;
      for (int k = 0; k < binds[j].size(); k++) 
        if (this->listAmylogenicData->Get(binds[j].at(k))->NumberAmylogenicRegions() > 0) 
          counterAmylSeqPart++;
  
      if (!binds[j].size()) continue;
      
      double percentPart = (double)((double)(counterAmylSeqPart*100)/(double)binds[j].size());
      
      if (!j) maximum = minimum = percentPart;
      
      if (percentPart < minimum) minimum = percentPart;
      if (percentPart > maximum) maximum = percentPart;
      
      average += percentPart;
      
    }
    
    average        /= (double)REPETITIONS;
    totalAverage   += average;
    minimumAverage += minimum;
    maximumAverage += maximum;
    
    fileOut.width(24); fileOut.left; fileOut << average << " |";
    fileOut.width(24); fileOut.left; fileOut << minimum << " |";
    fileOut.width(24); fileOut.left; fileOut << maximum << " |";
    
  }
  
  totalAverage   /= (double)REPETITIONS;
  minimumAverage /= (double)REPETITIONS;
  maximumAverage /= (double)REPETITIONS;
  
  fileOut.width(23); fileOut.left; fileOut << totalAverage << " |";
  fileOut.width(23); fileOut.left; fileOut << minimumAverage << " |";
  fileOut.width(23); fileOut.left; fileOut << maximumAverage << " |";
  fileOut.width(23); fileOut.left; fileOut << percentAmyloid - totalAverage << " |";
  
  fileOut << endl;
  
  fileOut.close();
  
  return true;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool ListAmylogenic::GetPercentOfSeqShuffleAmylogenicRegions(String* filenameOut) {

  if (!filenameOut || !filenameOut->Length()) return false;
  
  this->DeleteIncompleteData();
  
  fstream fileOut;
  int     sizePercent = (int)(PERCENTSPLIT * this->listAmylogenicData->Length() / 100);
  
  fileOut.open(filenameOut->Out(), fstream::out);
  
  if (!fileOut.is_open()) return false;

  fileOut.width(60); fileOut.left; fileOut << " Name |";
  fileOut.width(20); fileOut.left; fileOut << " Total Sequences |";
  fileOut.width(20); fileOut.left; fileOut << " Seq. Amyl. Reg. |";
  fileOut.width(20); fileOut.left; fileOut << " % |";
  fileOut.width(20); fileOut.left; fileOut << " Size of Part.(E) |";
  fileOut.width(21); fileOut.left; fileOut << " Number of Rep. (E) |";
  
  for (int i = 0; i < REPETITIONS; i++) {
    fileOut.width(23); fileOut.left; fileOut << " Average % in Rep. ";
    fileOut.width(2);  fileOut.left; fileOut << i + 1 << "|";
    fileOut.width(23); fileOut.left; fileOut << " Minimum % in Rep. ";
    fileOut.width(2);  fileOut.left; fileOut << i + 1 << "|";
    fileOut.width(23); fileOut.left; fileOut << " Maximum % in Rep. ";
    fileOut.width(2);  fileOut.left; fileOut << i + 1 << "|"; 
  }
  
  fileOut.width(25); fileOut.left; fileOut << " Average |";
  fileOut.width(25); fileOut.left; fileOut << " Minimun Average |";
  fileOut.width(25); fileOut.left; fileOut << " Maximun Average |";
  fileOut.width(25); fileOut.left; fileOut << " Error Average |";
  
  fileOut << endl;
  
  for (int i = 0; i < 1041; i++) fileOut << "_";
  fileOut << endl;
    
  fileOut.width(51); fileOut.left; fileOut << this->filenameOut->Out() << "Shuffle |";
  fileOut.width(18); fileOut.left; fileOut << this->listAmylogenicData->Length() << " |";
  
  int counterAmylSeq = 0;
  
  this->listAmylogenicData->SetInitial();
  while (this->listAmylogenicData->SetNext()) 
    if (this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegionsShuffle() > 0) 
      counterAmylSeq++;
  
  double percentAmyloid = (double)((double)(counterAmylSeq*100)/(double)this->listAmylogenicData->Length());
  
  fileOut.width(18); fileOut.left; fileOut << counterAmylSeq << " |";
  fileOut.width(18); fileOut.left; fileOut << percentAmyloid << " |";
  fileOut.width(18); fileOut.left; fileOut << sizePercent << " |";
  fileOut.width(19); fileOut.left; fileOut << REPETITIONS << " |";
  
  vector <int> arrList;
  double       totalAverage   = 0;
  double       minimumAverage = 0;
  double       maximumAverage = 0;
  
  for (int i = 0; i < REPETITIONS; i++) {
    
    arrList.clear();
    for (int j = 0; j < this->listAmylogenicData->Length(); j++) 
      arrList.push_back(j);
    
    int          numberBinds = (int)(this->listAmylogenicData->Length() / sizePercent) + (((this->listAmylogenicData->Length() % sizePercent))?1:0);
    double       minimum = 0, maximum = 0, average = 0;
    
    vector <int> binds[numberBinds];

    for (int j = 0; j < numberBinds; j++) { 
      int counterComplete = 0;
      while (arrList.size() && (++counterComplete <= sizePercent)) {
        int randomPosition = rand() % arrList.size();
        binds[j].push_back(arrList.at(randomPosition));
        arrList.erase(arrList.begin() + randomPosition);
      }
    }
    
    for (int j = 0; j < REPETITIONS; j++) {
     
      int counterAmylSeqPart = 0;
      for (int k = 0; k < binds[j].size(); k++) 
        if (this->listAmylogenicData->Get(binds[j].at(k))->NumberAmylogenicRegionsShuffle() > 0) 
          counterAmylSeqPart++;
  
      if (!binds[j].size()) continue;
      
      double percentPart = (double)((double)(counterAmylSeqPart*100)/(double)binds[j].size());
      
      if (!j) maximum = minimum = percentPart;
      
      if (percentPart < minimum) minimum = percentPart;
      if (percentPart > maximum) maximum = percentPart;
      
      average += percentPart;
      
    }
    
    average        /= (double)REPETITIONS;
    totalAverage   += average;
    minimumAverage += minimum;
    maximumAverage += maximum;
    
    fileOut.width(24); fileOut.left; fileOut << average << " |";
    fileOut.width(24); fileOut.left; fileOut << minimum << " |";
    fileOut.width(24); fileOut.left; fileOut << maximum << " |";
    
  }
  
  totalAverage   /= (double)REPETITIONS;
  minimumAverage /= (double)REPETITIONS;
  maximumAverage /= (double)REPETITIONS;
  
  fileOut.width(23); fileOut.left; fileOut << totalAverage << " |";
  fileOut.width(23); fileOut.left; fileOut << minimumAverage << " |";
  fileOut.width(23); fileOut.left; fileOut << maximumAverage << " |";
  fileOut.width(23); fileOut.left; fileOut << percentAmyloid - totalAverage << " |";
  
  fileOut << endl;
  
  fileOut.close();
  
  return true;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool ListAmylogenic::StatisticalOutComplete(String* filenameOut) {
  
  if (!filenameOut) return false;
  
  fstream fileOut;
  fileOut.open(filenameOut->Out(), fstream::out);
  
  if (!fileOut.is_open()) return false;
  
  fileOut << "ID #AR_Original AR_Size_Original %AR_Original #AR_Shuffle AR_Size_Shuffle %AR_Shuffle" << endl; 
  cout    << "ID #AR_Original AR_Size_Original %AR_Original #AR_Shuffle AR_Size_Shuffle %AR_Shuffle" << endl; 
    
  this->listAmylogenicData->SetInitial();
  while (this->listAmylogenicData->SetNext()) {
    
    fileOut << this->listAmylogenicData->GetCurrent()->Id()->Out() << " ";
    
    fileOut << this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegions()  << " ";
    fileOut << this->listAmylogenicData->GetCurrent()->SizeAmylogenicRegions()    << " ";
    fileOut << this->listAmylogenicData->GetCurrent()->PercentAmylogenicRegions() << " ";
    
    cout    << this->listAmylogenicData->GetCurrent()->Id()->Out() << " ";
    
    cout    << this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegions()  << " ";
    cout    << this->listAmylogenicData->GetCurrent()->SizeAmylogenicRegions()    << " ";
    cout    << this->listAmylogenicData->GetCurrent()->PercentAmylogenicRegions() << " ";
    
    if (this->listAmylogenicData->GetCurrent()->AmylogenicRegionsShuffle()->Length()) {

      fileOut << this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegionsShuffle()  << " ";
      cout    << this->listAmylogenicData->GetCurrent()->NumberAmylogenicRegionsShuffle()  << " ";
      
      fileOut << this->listAmylogenicData->GetCurrent()->SizeAmylogenicRegionsShuffle()    << " ";
      cout    << this->listAmylogenicData->GetCurrent()->SizeAmylogenicRegionsShuffle()    << " ";

      fileOut << this->listAmylogenicData->GetCurrent()->PercentAmylogenicRegionsShuffle() << " ";
      cout    << this->listAmylogenicData->GetCurrent()->PercentAmylogenicRegionsShuffle() << " ";
      
    }
    else { fileOut << "0 0 0"; cout << "0 0 0"; }
    
    fileOut << endl;
    cout    << endl;

  }

  fileOut.close();
  
  return true;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void ListAmylogenic::DeleteIncompleteData(void) {
  
  for (int i = this->listAmylogenicData->Length() - 1; i >= 0; i--) {
    
    if (!(this->listAmylogenicData->Get(i)->Id()->Length()) ||
        !(this->listAmylogenicData->Get(i)->Description()->Length())) 
      this->listAmylogenicData->Delete(i);
    
  }
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
